package com.ebt.m.customer.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.customer.util.DisplayUtil;

public class CustomerInfoUnitTextView4Age extends LinearLayout{

	private static final int DEFAULT_TEXT_VIEW_TEXT_TITLE_COLOR = 0xff000000;
	private static final int DEFAULT_TEXT_VIEW_TEXT_CONTENT_COLOR = 0xff000000;
    private static final int DEFAULT_EDIT_TEXT_HINT_COLOR = 0xffbbbbbb;

	private static final int DEFAULT_TEXT_VIEW_TEXT_TITLE_SIZE_SP = 16;
	private static final int DEFAULT_TEXT_VIEW_TEXT_CONTENT_SIZE_SP = 16;

	private Context mContext;

	private String mTextViewTextTitle;
	private String mTextViewTextContent;

    private int mEditTextHintColor = DEFAULT_EDIT_TEXT_HINT_COLOR;
	private int mTextViewTextTitleColor = -1;
	private float mTextViewTextTitleSize = -1;

	private int mTextViewTextContentColor = -1;
	private float mTextViewTextContentSize = -1;

	private TextView customer_info_unit_textview_title;
	private TextView customer_info_unit_textview_content;
    private ImageView customer_info_unit_imageview;
    private RelativeLayout age_rl;

    private boolean mShowImageView = false;
    private int mTitleTextViewWidth = 0;

	public CustomerInfoUnitTextView4Age(Context context) {
		this(context, null);
	}

	public CustomerInfoUnitTextView4Age(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}
    private String mEditTextHint;
	public CustomerInfoUnitTextView4Age(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		View contentView = inflate(context, R.layout.view_customer_info_unit_text_view_4_age, this);

		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.customerInfoUnit);

		final int count = a.getIndexCount();
        for (int i = 0; i < count; ++i) {
            int attr = a.getIndex(i);
            switch (attr) {
            case R.styleable.customerInfoUnit_customerInfoUnitText:
            	mTextViewTextTitle = a.getString(attr);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitEditTextColor:
            	mTextViewTextContentColor = a.getColor(attr, DEFAULT_TEXT_VIEW_TEXT_CONTENT_COLOR);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitEditTextSize:
            	mTextViewTextContentSize = a.getDimensionPixelSize(attr, DisplayUtil.sp2px(mContext, DEFAULT_TEXT_VIEW_TEXT_CONTENT_SIZE_SP));
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitShowImage:
                mShowImageView = a.getBoolean(attr, false);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitTextColor:
            	mTextViewTextTitleColor = a.getColor(attr, DEFAULT_TEXT_VIEW_TEXT_TITLE_COLOR);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitTextSize:
            	mTextViewTextTitleSize = a.getDimensionPixelSize(attr, DisplayUtil.sp2px(mContext, DEFAULT_TEXT_VIEW_TEXT_TITLE_SIZE_SP));
            	break;
            case R.styleable.customerInfoUnit_customerInfoUnitHintColor:
                mEditTextHintColor = a.getColor(attr, DEFAULT_EDIT_TEXT_HINT_COLOR);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitHint:
                mEditTextHint = a.getString(attr);
                break;
            case R.styleable.customerInfoUnit_customerInfoUnitTitleWidth:
                mTitleTextViewWidth = a.getDimensionPixelOffset(attr, 0);
                break;

            }
        }
        a.recycle();

        customer_info_unit_textview_title = (TextView)contentView.findViewById(R.id.customer_info_unit_textview_title);
        customer_info_unit_textview_content = (TextView)contentView.findViewById(R.id.customer_info_unit_textview_content);
        customer_info_unit_imageview = (ImageView)contentView.findViewById(R.id.customer_info_unit_imageview);
        age_rl = (RelativeLayout)contentView.findViewById(R.id.age_rl);

        if(mTitleTextViewWidth > 0) {
            customer_info_unit_textview_title.setWidth(mTitleTextViewWidth);
        }
        if(mShowImageView){
            customer_info_unit_imageview.setVisibility(View.VISIBLE);
        }else{
            customer_info_unit_imageview.setVisibility(View.GONE);
        }

        if(!TextUtils.isEmpty(mTextViewTextTitle)){
        	customer_info_unit_textview_title.setText(mTextViewTextTitle);
        }

        if(!TextUtils.isEmpty(mTextViewTextContent)){
        	customer_info_unit_textview_content.setText(mTextViewTextContent);
        }
        if(mTextViewTextContentColor >= 0){
        	customer_info_unit_textview_content.setTextColor(mTextViewTextContentColor);
        }
		if(mTextViewTextContentSize >= 0){
			customer_info_unit_textview_content.setTextSize(DisplayUtil.px2sp(mContext, mTextViewTextContentSize));
		}
		if(mTextViewTextTitleColor >= 0){
			customer_info_unit_textview_title.setTextColor(mTextViewTextTitleColor);
		}
		if(mTextViewTextTitleSize >= 0){
			customer_info_unit_textview_title.setTextSize(DisplayUtil.px2sp(mContext, mTextViewTextTitleSize));
		}
        if(!TextUtils.isEmpty(mEditTextHint)){
            customer_info_unit_textview_content.setHint(mEditTextHint);
        }
        customer_info_unit_textview_content.setHintTextColor(mEditTextHintColor);
	}

	public void setTextViewTextTitle(String text){
		mTextViewTextTitle = text;
		if(customer_info_unit_textview_title != null){
			customer_info_unit_textview_title.setText(mTextViewTextTitle);
		}
	}

	public void setTextViewTextContent(String text){
		mTextViewTextContent = text;
		if(customer_info_unit_textview_content != null){
			customer_info_unit_textview_content.setText(mTextViewTextContent);
		}
	}

	public String getTextViewTextTitle(){
		return (String) customer_info_unit_textview_title.getText();
	}

	public String getTextViewTextContent(){
		return (String) customer_info_unit_textview_content.getText();
	}

	public void setTextViewContentOnClickListener(OnClickListener listener, Object tag){
//		customer_info_unit_textview_content.setTag(tag);
//		customer_info_unit_textview_content.setOnClickListener(listener);
        age_rl.setTag(tag);
        age_rl.setOnClickListener(listener);
	}
	
	
	public TextView getTitleTextView(){
        return customer_info_unit_textview_title;
	}
	
	public TextView getContentTextView(){
		return customer_info_unit_textview_content;
	}
}
